import Reflux from "reflux"
import BaseAction, {addDefaultListerns} from "@/base/BaseAction";
import GUtils from "@/utils/ajax";

const prefix = "/resource/advertisement/";
const api = {
    search: prefix + "search",
    create: prefix + "create",
    edit: prefix + "edit",
    detail: prefix + "detail",
    enabled: prefix + "enabled",
    getWxPageList: prefix + "getWxPageList",
    getDocFileList: prefix + "getDocFileList",
    getRichTextList: prefix + "getRichTextList"
};

const createAction = () => {
    const Action = Reflux.createActions({
        ...BaseAction,
        getWxPageList:{asyncResult: true},
        getDocFileList:{asyncResult: true},
        getRichTextList:{asyncResult: true},
    });

    addDefaultListerns(Action, api)


    Action.getWxPageList.listen(function () {
        GUtils.Ajax.post(api.getWxPageList, {}).then(this.completed, this.failed);
    });
    Action.getDocFileList.listen(function () {
        GUtils.Ajax.post(api.getDocFileList, {}).then(this.completed, this.failed);
    });
    Action.getRichTextList.listen(function () {
        GUtils.Ajax.post(api.getRichTextList, {}).then(this.completed, this.failed);
    });
    return Action;
};

export {api, createAction}